/*
 * Created by IntelliJ IDEA.
 * User: amrk
 * Date: 13/02/2005
 * Time: 11:40:55
 */
package com.talios.jira.idea.actions;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataConstants;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.IconLoader;
import com.talios.jira.browser.IssueSearch;
import com.talios.jira.feeds.FeedBuilder;
import com.talios.jira.feeds.QuickSearchFeedBuilder;
import com.talios.jira.idea.JiraConfigurationComponent;

public class SearchIssueAction extends JIRAAction {

    public void actionPerformed(AnActionEvent event) {
        final Project project = (Project) event.getDataContext().getData(DataConstants.PROJECT);

        FeedBuilder feedBuilder = null;

        JiraConfigurationComponent config = project.getComponent(JiraConfigurationComponent.class);
        if (config.supportsRpc()) {
            IssueSearch issueSearch = new IssueSearch(project);
            feedBuilder = issueSearch.getFeedBuilder();
        } else {
            String searchFor = Messages.showInputDialog(project, "Search for Issues Containing", "Search", IconLoader.getIcon("/actions/find.png"));

            if (searchFor != null) {
                feedBuilder = new QuickSearchFeedBuilder(searchFor);
            }
        }

        if (feedBuilder != null) {
            config.openSearch(feedBuilder, false);
        }
    }

}